﻿using DevExpress.ExpressApp;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;

namespace Tida.Module.BusinessObjects.系统管理
{
    [NonPersistent]
    public class MailHelper
    {


        public static void ShowMsg()
        {




        }


        public static void sendGroupMail(string 角色, Session sess, string 标题, string 正文)
        {


            var rolea = new XPQuery<Sys_Role>(sess).Where(mm => mm.Name == 角色).FirstOrDefault().Sys_Users.ToList();


            foreach (var oo in rolea)
            {

                sendMail(oo.邮件地址, 正文, 标题);

            }


        }
        public static void sendMail(string 接收邮箱, string 邮件正文, string 邮件标题)
        {

            using (MailMessage mailMessage = new MailMessage())
            {

                if (接收邮箱 != "" && 接收邮箱 != string.Empty)
                {
                    using (SmtpClient smtpClient = new SmtpClient("smtpcom.263xmail.com", 25))
                    {



                        mailMessage.To.Add(接收邮箱);

                        mailMessage.Body = 邮件正文;

                        mailMessage.From = new MailAddress("sysapp@tida-lighting.net");

                        mailMessage.Subject = 邮件标题;

                        smtpClient.Credentials = new System.Net.NetworkCredential("sysapp@tida-lighting.net", "tida@2016");//如果启用了“客户端授权码”，要用授权码代替密码 

                        smtpClient.Send(mailMessage);

                    }
                }
            }

        }

    }
}
